var userdb = require('../../db/user.db');
var emit = require('../../emit');
var async = require('async');

function onsocket(socket,data){
    console.log("账号启用=1、禁用=0:" + data.active + "," + data.user);
    async.waterfall([
        (callback)=>{
            userdb.getuser(data.user,(err,info) =>{
                callback(err,info);
            });
        },
        (info,callback)=>{
            info.active = data.active;
            userdb.setuser(data.user,info,(err) =>{
                callback(err);
            })
        }
    ],(err)=>{
        if(err){
            emit.send(socket,"activeuser", {result:false,info:err});
        }else{
            emit.send(socket,"activeuser", {result:true,info:''});
        }
    });
}

module.exports = {
    onsocket
}